package expression;

import vm.runtime.NextVMRuntime;

import java.util.ArrayList;
import java.util.Arrays;

public class ListExpression {
    public static ArrayList<Object> getArrays(
            String run_code ,
            String Type ,
            NextVMRuntime nextVMRuntime)
        throws Exception {
        run_code = run_code.trim();
        if (run_code.startsWith("[") && run_code.endsWith("]")) {
            /*
              String[] tokens = run_code.substring(1,run_code.length()-1).split(
                    ",(?=([^\"]*\"[^\"]*\")*[^\"]*$)(?=([^(]*\\([^)]*\\))*[^)]*$)"
            );
             */
            String[] tokens = StringExpression.splitStringTokens(run_code.substring(1,run_code.length()-1));
            Object[] objects = BaseExpression.Deal(tokens , nextVMRuntime);
            return new ArrayList<>(Arrays.asList(objects));
        }
        else {
            ArrayList<Object> arrayList = (ArrayList<Object>) BaseExpression.Deal(new String[]{run_code} , nextVMRuntime)[0];
            return (ArrayList<Object>) BaseExpression.Deal(new String[]{run_code} , nextVMRuntime)[0];
        }
    }
}
